package com.zdkj.subway.check.controller.subwayRat.TVMRevenueVarianceAudit.TvmChaYiDXC.tvmCengJiCYXC.tvmXianJinCengJiCYDXC;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zdkj.common.core.constant.SecurityConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.check.controller.CommonController;
import com.zdkj.subway.check.entity.*;
import com.zdkj.subway.check.enums.ResultDetailMsg;
import com.zdkj.subway.check.fegin.SubwayStmService;
import com.zdkj.subway.check.mapper.*;
import com.zdkj.subway.check.result.Result;
import com.zdkj.subway.check.service.FareDifferencesInAuditService;
import com.zdkj.subway.check.service.impl.subwayRat.TVMRevenueVarianceAudit.TvmChaYiDXC.tvmCengJiCYXC.tvmXianJinCengJiCYDXC.TvmXianJinCengJiCYDXCService;
import com.zdkj.subway.check.util.DateFormat;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * tvm现金层级
 */
@RestController
@AllArgsConstructor
@RequestMapping("/check")
@Slf4j
public class TvmXianJinCengJiCYDXCController {

    private final SubwayStmService subwayStmService;
    @Resource
    private TvmXianJinCengJiCYDXCService tvmXianJinCengJiCYDXCService;
    @Resource
    private CashboxUninstallMapper cashboxUninstallMapper;
    @Resource
    private SwAuTvmBoxAmountDifferenceMapper swAuTvmBoxAmountDifferenceMapper;
    @Resource
    private SwAuTvmMoneyAssistMapper swAuTvmMoneyAssistMapper;
    @Resource
    SwAuTvmCashAmountHierarchyDifferenceMapper swAuTvmCashAmountHierarchyDifferenceMapper;
    @Resource
    SwAuTvmCashboxAmountHierarchyDifferenceMapper swAuTvmCashboxAmountHierarchyDifferenceMapper;
    @Resource
    SwAuTvmAmountDefferenceMapper swAuTvmAmountDefferenceMapper;
    @Resource
    SwAuItvmOnlineAmountHierarchyDifferenceMapper swAuItvmOnlineAmountHierarchyDifferenceMapper;
    @Autowired
    private CommonController commonController;
    @Autowired
    private FareDifferencesInAuditService fareDifferencesInAuditService;

    /**
     * 结账单据与SC层级差异待协查
     * @param page
     * @param swIfTxnTicketTransactionStatistics
     * @return
     */
    @RequestMapping("/getSwAuTvmCashAmountHierarchyDifferenceList")
    @ApiOperation(value = "结账单据与SC层级差异待协查", notes = "结账单据与SC层级差异待协查")
    public Page getSwAuTvmCashAmountHierarchyDifferenceList(Page page, SwAuTvmCashAmountHierarchyDifference swIfTxnTicketTransactionStatistics){
        List<Map<String,Object>> res=tvmXianJinCengJiCYDXCService.getSwAuTvmCashAmountHierarchyDifferenceList(swIfTxnTicketTransactionStatistics);
        page.setData(res,true);
        return page;
    }

    /**
     * 现金层级下发
     * @param param
     * @return
     */
    @RequestMapping("/sendStatusSwAuTvmCashAmountHierarchyDifference")
    @ApiOperation(value = "现金层级下发", notes = "现金层级下发")
    @Transactional(rollbackFor = Exception.class)
    public Result sendStatusSwAuTvmCashAmountHierarchyDifference(@RequestBody Map<String,Object> param){
        PigxUser user = SecurityUtils.getUser();
        String ids = String.valueOf(param.get("ids"));
        Result res=new Result(ResultDetailMsg.OK);
        try {
            for (String id : ids.split(",")) {
                SwAuTvmCashAmountHierarchyDifference swAuTvmCashAmountHierarchyDifference = swAuTvmCashAmountHierarchyDifferenceMapper.selectById(Integer.parseInt(id));
                swAuTvmCashAmountHierarchyDifference.setAssistStatus("2");
                swAuTvmCashAmountHierarchyDifference.setQfReplyStatus("0");
                swAuTvmCashAmountHierarchyDifference.setReplyStatus("0");//下发未回馈
                swAuTvmCashAmountHierarchyDifference.setSendAssistTime(new Date());
                swAuTvmCashAmountHierarchyDifference.setSendPersonCode(user.getUserCode());//下发人工号
                swAuTvmCashAmountHierarchyDifference.setSendPersonName(user.getNikeName());//下发人
                swAuTvmCashAmountHierarchyDifferenceMapper.updateById(swAuTvmCashAmountHierarchyDifference);
            }
            //lc-acc暂时不发代办
            if(!"0".equals(param.get("type"))){
                commonController.innerBatch(param);
            }
        }catch (Exception e){
            log.error("{}",e);
            res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            res.setMsg("数据下发失败！");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return res;
    }

    /**
     * 批量删除SC-LC未下发的
     * @param idList
     * @return
     */
    @SysLog("通过id批量删除SC-LC未下发的")
    @DeleteMapping("/batchScLcDel")
    @ApiOperation(value = "通过id批量删除SC-LC未下发的", notes = "通过id批量删除SC-LC未下发的")
    @Transactional(rollbackFor = Exception.class)
    public R batchRemoveScLcById(@RequestBody List<Integer> idList) {
        List<SwAuTvmCashAmountHierarchyDifference> list = swAuTvmCashAmountHierarchyDifferenceMapper.selectList(new QueryWrapper<SwAuTvmCashAmountHierarchyDifference>().lambda().in(SwAuTvmCashAmountHierarchyDifference::getId, idList));
        //删除之前需要改变审核表的加入协查状态为未加入 '0'
        List<Integer> integerList = list.stream().map(SwAuTvmCashAmountHierarchyDifference::getRelationSourceId).collect(Collectors.toList());
        FareDifferencesInAudit fareDifferencesInAudit = new FareDifferencesInAudit();
        fareDifferencesInAudit.setIsAddLcLevelAssist("0");
        UpdateWrapper<FareDifferencesInAudit> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id",integerList);
        fareDifferencesInAuditService.update(fareDifferencesInAudit,updateWrapper);
        //执行删除
        return R.ok(swAuTvmCashAmountHierarchyDifferenceMapper.deleteBatchIds(idList));
    }

    /**
     * 批量删除LC--ACC未下发的
     * @param idList
     * @return
     */
    @SysLog("通过id批量删除LC--ACC未下发的")
    @DeleteMapping("/batchLcAccDel")
    @ApiOperation(value = "通过id批量删除LC--ACC未下发的", notes = "通过id批量删除LC--ACC未下发的")
    @Transactional(rollbackFor = Exception.class)
    public R batchRemoveLcAccById(@RequestBody List<Integer> idList) {
        List<SwAuTvmCashAmountHierarchyDifference> list = swAuTvmCashAmountHierarchyDifferenceMapper.selectList(new QueryWrapper<SwAuTvmCashAmountHierarchyDifference>().lambda().in(SwAuTvmCashAmountHierarchyDifference::getId, idList));
        //删除之前需要改变审核表的加入协查状态为未加入 '0'
        List<Integer> integerList = list.stream().map(SwAuTvmCashAmountHierarchyDifference::getRelationSourceId).collect(Collectors.toList());
        FareDifferencesInAudit fareDifferencesInAudit = new FareDifferencesInAudit();
        fareDifferencesInAudit.setIsAddAccLevelAssist("0");
        UpdateWrapper<FareDifferencesInAudit> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id",integerList);
        fareDifferencesInAuditService.update(fareDifferencesInAudit,updateWrapper);
        //执行删除
        return R.ok(swAuTvmCashAmountHierarchyDifferenceMapper.deleteBatchIds(idList));
    }

    /**
     * 分钱箱
     * @param page
     * @param param
     * @return
     */
    @RequestMapping("/getSwAuTvmCashboxAmountHierarchyDifferenceList")
    @ApiOperation(value = "分钱箱", notes = "分钱箱")
    public Page getSwAuTvmCashboxAmountHierarchyDifferenceList(@RequestParam Map<String,String> param,Page page){
        List<Map<String,Object>> res=tvmXianJinCengJiCYDXCService.getSwAuTvmCashboxAmountHierarchyDifferenceList(param);
        page.setData(res,true);
        return page;
    }

    /**
     * itvm
     * @param page
     * @param swAuItvmOnlineAmountHierarchyDifference
     * @return
     */
    @RequestMapping("/getSwAuItvmOnlineAmountHierarchyDifferenceList")
    @ApiOperation(value = "itvm", notes = "itvm")
    public Page getSwAuItvmOnlineAmountHierarchyDifferenceList(Page page, SwAuItvmOnlineAmountHierarchyDifference swAuItvmOnlineAmountHierarchyDifference){
        List<Map<String,Object>> res=tvmXianJinCengJiCYDXCService.getSwAuItvmOnlineAmountHierarchyDifferenceList(swAuItvmOnlineAmountHierarchyDifference);
        page.setData(res,true);
        return page;
    }


    /**
     * 钱箱未卸载设置入账日期
     * @param cashboxUninstall
     * @param ids
     * @return
     */
    @RequestMapping("/setCashboxUninstallPostDate")
    @ApiOperation(value = "钱箱未卸载设置入账日期", notes = "钱箱未卸载设置入账日期")
    public Result setCashboxUninstallPostDate(SwStInputCashboxUninstalled cashboxUninstall, String ids){
        Result res=new Result(ResultDetailMsg.OK);
        try{
            UpdateWrapper<SwStInputCashboxUninstalled> uninstallUpdateWrapper=new UpdateWrapper<>();
            uninstallUpdateWrapper.in("id", ids.split(","));
            cashboxUninstall.setUpdateTime(new Date());
            int update = cashboxUninstallMapper.update(cashboxUninstall, uninstallUpdateWrapper);
            String[] idParam = ids.split(",");
            for(String item : idParam){
                SwStInputCashboxUninstalled sw =cashboxUninstallMapper.selectById(item);
                String lineCode = sw.getLineCode();
                String stationCode = sw.getStationCode();
                String statisticsDate = DateFormat.date_ex_str(cashboxUninstall.getPostDate());				
                //修改入账日期更新车站营收日报表
                subwayStmService.refreshStationincome(lineCode,stationCode,statisticsDate,SecurityConstants.FROM_IN);		
                
            }
            return res;
        }catch (Exception e){
            log.error("{}=>{}","钱箱未写载设置入账日期失败！",e);
            res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            res.appendMsg("钱箱未写载设置入账日期失败");
            return res;
        }
    }


    /**
     * 获取票款差异分钱箱信息
     * @param ids
     * @return
     */
    @RequestMapping("/getSwAuTvmBoxAmountDifference")
    @ApiOperation(value = "获取票款差异分钱箱信息", notes = "获取票款差异分钱箱信息")
    public Result getSwAuTvmBoxAmountDifference(@RequestParam Map<String,String> param, String ids){
        Result result=new Result(ResultDetailMsg.OK);
        try{
            List<Map<String,Object>> res=swAuTvmMoneyAssistMapper.getTvmTicketCYXCList(param);
            result.setData(res);
            return result;
        }catch (Exception e){
            log.error("{}=>{}","查询数据失败！",e);
            result.setResult(ResultDetailMsg.CHECK_SELECT_ERROR);
            result.setMsg("查询数据失败");
            return result;
        }
    }

    /**
     * 修改替换票款差异分钱箱信息数据
     * @param ids
     * @return
     */
    @RequestMapping("/updateSwAuTvmBoxAmountDifference")
    @ApiOperation(value = "修改替换票款差异分钱箱信息数据", notes = "修改替换票款差异分钱箱信息数据")
    public Result updateSwAuTvmBoxAmountDifference(String ids){ //,SwAuTvmMoneyAssist auTvmMoneyAssist
        Result res=new Result(ResultDetailMsg.OK);
        try{
            QueryWrapper<SwAuTvmMoneyAssist> queryWrapper=new QueryWrapper<>();
            queryWrapper.in("id",ids.split(","));
            List<SwAuTvmMoneyAssist> swAuTvmMoneyAssists = swAuTvmMoneyAssistMapper.selectList(queryWrapper);
            for(SwAuTvmMoneyAssist auTvmMoneyAssist:swAuTvmMoneyAssists){
            SwAuTvmBoxAmountDifference swAuTvmBoxAmountDifference = swAuTvmBoxAmountDifferenceMapper.selectById(auTvmMoneyAssist.getRelationid());
//            SwAuTvmBoxAmountDifference swAuTvmBoxAmountDifference = JSONObject.parseObject(details, SwAuTvmBoxAmountDifference.class);
            if(swAuTvmBoxAmountDifference.getAuditStatus().equals("1")){
                res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
                res.setMsg("钱箱票款已审核，不能再做一键替换");
                return res;
            }
            swAuTvmBoxAmountDifference.setReplyActualMoney(auTvmMoneyAssist.getReplyActualMoney());
            swAuTvmBoxAmountDifference.setReplySupplementMoney(auTvmMoneyAssist.getReplySupplementMoney());
            swAuTvmBoxAmountDifference.setReplyHandOutMoney(auTvmMoneyAssist.getReplyHandOutMoney());
            swAuTvmBoxAmountDifference.setReplyUnloadDisplayMoney(auTvmMoneyAssist.getReplyDsiplayMoney());
            if(swAuTvmBoxAmountDifference.getDataSource()!=null && swAuTvmBoxAmountDifference.getDataSource().equals("5")){
                swAuTvmBoxAmountDifference.setSystemMoney(auTvmMoneyAssist.getSystemMoney());
				/*
                BigDecimal systemMoney = auTvmMoneyAssist.getReplyActualMoney().subtract(auTvmMoneyAssist.getReplySupplementMoney()).add(auTvmMoneyAssist.getReplyHandOutMoney());
                //差异金额为 （卸载实点金额-补币金额+手工清出金额）-系统金额
                BigDecimal diffMoney = swAuTvmBoxAmountDifference.getActualMoney().
                        subtract(swAuTvmBoxAmountDifference.getSupplementMoney()).add(swAuTvmBoxAmountDifference.getHandOutMoney()).subtract(systemMoney);*/ 
                BigDecimal systemMoney = auTvmMoneyAssist.getReplyActualMoney().add(auTvmMoneyAssist.getReplyHandOutMoney());
                //差异金额为 （卸载实点金额-补币金额+手工清出金额）-系统金额
                BigDecimal diffMoney = swAuTvmBoxAmountDifference.getActualMoney().add(swAuTvmBoxAmountDifference.getHandOutMoney()).subtract(systemMoney);
                swAuTvmBoxAmountDifference.setDiffMoney(diffMoney);
            }
			/*
			 if(swAuTvmBoxAmountDifference.getDataSource()!=null && swAuTvmBoxAmountDifference.getDataSource().equals("6")){ //来源于分钱箱审核 20241023
                swAuTvmBoxAmountDifference.setSystemMoney(auTvmMoneyAssist.getSystemMoney());
				
                BigDecimal systemMoney = auTvmMoneyAssist.getReplyActualMoney().add(auTvmMoneyAssist.getReplyHandOutMoney());
                //差异金额为 （卸载实点金额-补币金额+手工清出金额）-系统金额
                BigDecimal diffMoney = swAuTvmBoxAmountDifference.getActualMoney().add(swAuTvmBoxAmountDifference.getHandOutMoney()).subtract(systemMoney);
                swAuTvmBoxAmountDifference.setDiffMoney(diffMoney);
            }*/
            int i = swAuTvmBoxAmountDifferenceMapper.updateById(swAuTvmBoxAmountDifference);
            auTvmMoneyAssist.setReplaceStatus("1");
            int i1 = swAuTvmMoneyAssistMapper.updateById(auTvmMoneyAssist);
            }
        }catch (Exception e){
            log.error("{}=>{}","分钱箱信息替换失败！",e);
            res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            res.appendMsg("分钱箱信息替换失败！");
        }
        return res;
    }

    /**
     * 票款差异层级分钱箱下发
     * @param param
     * @return
     */
    @RequestMapping("/sendStatusSwAuTvmCashboxAmountHierarchyDifference")
    @ApiOperation(value = "票款差异层级分钱箱下发", notes = "票款差异层级分钱箱下发")
    @Transactional(rollbackFor = Exception.class)
    public Result sendStatusSwAuTvmCashboxAmountHierarchyDifference(@RequestBody Map<String,Object> param){
        String ids = String.valueOf(param.get("ids"));
        Result res=new Result(ResultDetailMsg.OK);
        try {
            for (String id : ids.split(",")) {
                SwAuTvmCashboxAmountHierarchyDifference swAuTvmCashboxAmountHierarchyDifference = swAuTvmCashboxAmountHierarchyDifferenceMapper.selectById(Integer.parseInt(id));
                swAuTvmCashboxAmountHierarchyDifference.setAssistStatus("2");
                swAuTvmCashboxAmountHierarchyDifference.setSendAssistTime(new Date());
                swAuTvmCashboxAmountHierarchyDifferenceMapper.updateById(swAuTvmCashboxAmountHierarchyDifference);
            }
            commonController.innerBatch(param);
        }catch (Exception e){
            log.error("{}",e);
            res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            res.setMsg("数据下发失败！");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return res;
    }
    /**
     * 替换票款差异分钱箱审核主表
     * @param ids
     * @return
     */
    @RequestMapping("/replaceSwAuTvmBoxAmountDifference")
    @ApiOperation(value = "替换票款差异分钱箱审核主表", notes = "替换票款差异分钱箱审核主表")
    public Result replaceSwAuTvmBoxAmountDifference(String ids/*,SwAuTvmCashboxAmountHierarchyDifference swAuTvmCashboxAmountHierarchyDifference*/,String tableDataSource){
        Result result=new Result(ResultDetailMsg.OK);
        try {
            for(String id:ids.split(",")) {
                //查询TVM票款差异协查-现金层级差异-分钱箱信息
                SwAuTvmCashboxAmountHierarchyDifference swAuTvmCashboxAmountHierarchyDifference = swAuTvmCashboxAmountHierarchyDifferenceMapper.selectById(Integer.parseInt(id));
                //查询TVM票款差异分钱箱差异审核
                SwAuTvmBoxAmountDifference swAuTvmBoxAmountDifference = swAuTvmBoxAmountDifferenceMapper.selectById(swAuTvmCashboxAmountHierarchyDifference.getRelationSourceboxId());
                String auditStatus = swAuTvmBoxAmountDifference.getAuditStatus();
                if (StringUtils.isNotEmpty(auditStatus) && auditStatus.equals("1")) { //已经审核的数据
                    result.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
                    result.setMsg("收入已审核，不能再做一键替换");
                    return result;
                }
                swAuTvmBoxAmountDifference.setScSaleAmount(swAuTvmCashboxAmountHierarchyDifference.getReplySystemAmount()); //存放清点金额
                if (swAuTvmBoxAmountDifference.getDataSource().equals("2")) { //分钱箱票款审核
                    /*
					BigDecimal replySystemAmount = swAuTvmCashboxAmountHierarchyDifference.getReplySystemAmount();
                    swAuTvmBoxAmountDifference.setSystemMoney(replySystemAmount); //重新计算系统金额
                    BigDecimal add = swAuTvmBoxAmountDifference.getActualMoney().subtract(swAuTvmBoxAmountDifference.getSupplementMoney()).add(swAuTvmBoxAmountDifference.getHandOutMoney());
                    */
					BigDecimal replySystemAmount = swAuTvmCashboxAmountHierarchyDifference.getReplySystemAmount();
                    swAuTvmBoxAmountDifference.setSystemMoney(replySystemAmount); //重新计算系统金额
                    BigDecimal add = swAuTvmBoxAmountDifference.getActualMoney().add(swAuTvmBoxAmountDifference.getHandOutMoney());
					BigDecimal diffMoney = add.subtract(replySystemAmount);//差异金额 实点-系统
                    swAuTvmBoxAmountDifference.setDiffMoney(diffMoney);//存放差异金额
                }
                //批量更新
                int i = swAuTvmBoxAmountDifferenceMapper.updateById(swAuTvmBoxAmountDifference);
                SwAuTvmCashboxAmountHierarchyDifference s = new SwAuTvmCashboxAmountHierarchyDifference();
                s.setId(swAuTvmCashboxAmountHierarchyDifference.getId());
                s.setReplaceStatus("1");
                //批量更新
                swAuTvmCashboxAmountHierarchyDifferenceMapper.updateById(s);
            }
        }catch (Exception e){
            log.error("{}",e);
            result.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            result.appendMsg("票款差异分钱箱审核主表替换失败！");
        }
        return result;
    }


    /**
     * itvm下发
     * @param param
     * @return
     */
    @RequestMapping("/sendStatusSwAuItvmOnlineAmountHierarchyDifference")
    @ApiOperation(value = "itvm下发", notes = "itvm下发")
    @Transactional(rollbackFor = Exception.class)
    public Result sendStatusSwAuItvmOnlineAmountHierarchyDifference(@RequestBody Map<String,Object> param){
        String ids = String.valueOf(param.get("ids"));
        Result res=new Result(ResultDetailMsg.OK);
        try {
            for (String id : ids.split(",")) {
                SwAuItvmOnlineAmountHierarchyDifference swAuItvmOnlineAmountHierarchyDifference = swAuItvmOnlineAmountHierarchyDifferenceMapper.selectById(Integer.parseInt(id));
                swAuItvmOnlineAmountHierarchyDifference.setAssistStatus("2");
                swAuItvmOnlineAmountHierarchyDifference.setQfReplyStatus("0");
                swAuItvmOnlineAmountHierarchyDifference.setSendAssistTime(new Date());
                swAuItvmOnlineAmountHierarchyDifferenceMapper.updateById(swAuItvmOnlineAmountHierarchyDifference);
            }
            commonController.innerBatch(param);
        }catch (Exception e){
            log.error("{}",e);
            res.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            res.setMsg("数据下发失败！");
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return res;
    }



    /**
     * itvm替换差异审核主表替换来源值
     * @param ids
     * @return
     */
    @RequestMapping("/replaceSwAuItvmOnlineAmountHierarchyDifference")
    @ApiOperation(value = "itvm替换差异审核主表替换来源值", notes = "itvm替换差异审核主表替换来源值")
    public Result replaceSwAuTvmAmountDefference(String ids/*,SwAuItvmOnlineAmountHierarchyDifference swAuItvmOnlineAmountHierarchyDifference*/,String tableDataSource){
        Result result=new Result(ResultDetailMsg.OK);
        try {
            for(String id:ids.split(",")){
                //ITVM票款差异协查-层级差异信息
                SwAuItvmOnlineAmountHierarchyDifference swAuItvmOnlineAmountHierarchyDifference = swAuItvmOnlineAmountHierarchyDifferenceMapper.selectById(Integer.parseInt(id));
                //TVM票款差异审核
                SwAuTvmAmountDefference fareDifferencesInAudit = swAuTvmAmountDefferenceMapper.selectById(swAuItvmOnlineAmountHierarchyDifference.getRelationSourceId());
            String auditStatus = fareDifferencesInAudit.getAuditStatus();
                //已经审核的数据
            if(StringUtils.isNotEmpty(auditStatus) && auditStatus.equals("1")){
                result.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
                result.setMsg("收入已审核，不能再做一键替换");
                return result;
            }
//            FareDifferencesInAudit fareDifferencesInAudit=new FareDifferencesInAudit();
            fareDifferencesInAudit.setId(swAuItvmOnlineAmountHierarchyDifference.getRelationSourceId());
                //sc
            if("2".equals(tableDataSource)){
                fareDifferencesInAudit.setScElecRecharge(swAuItvmOnlineAmountHierarchyDifference.getReplyRechargeMoney());
                fareDifferencesInAudit.setScElecReturn(swAuItvmOnlineAmountHierarchyDifference.getReplyErrorReturnMoney());
                fareDifferencesInAudit.setScElecSellTicket(swAuItvmOnlineAmountHierarchyDifference.getReplySaleMoney());
            }
            //sc-lc
            else if("3".equals(tableDataSource)){
                fareDifferencesInAudit.setScElecRecharge(swAuItvmOnlineAmountHierarchyDifference.getReplyRechargeMoney());
                fareDifferencesInAudit.setScElecReturn(swAuItvmOnlineAmountHierarchyDifference.getReplyErrorReturnMoney());
                fareDifferencesInAudit.setScElecSellTicket(swAuItvmOnlineAmountHierarchyDifference.getReplySaleMoney());
            }
            //lc-ACC
            else if("4".equals(tableDataSource)){
                fareDifferencesInAudit.setLcElecRecharge(swAuItvmOnlineAmountHierarchyDifference.getReplyRechargeMoney());
                fareDifferencesInAudit.setLcElecReturn(swAuItvmOnlineAmountHierarchyDifference.getReplyErrorReturnMoney());
                fareDifferencesInAudit.setLcElecSellTicket(swAuItvmOnlineAmountHierarchyDifference.getReplySaleMoney());

                //新加的对比回馈字段为ACC
                fareDifferencesInAudit.setAccElecRecharge(swAuItvmOnlineAmountHierarchyDifference.getReplyComparativeRechargeMoney());
                fareDifferencesInAudit.setAccElecReturn(swAuItvmOnlineAmountHierarchyDifference.getReplyComparativeErrorReturnMoney());
                fareDifferencesInAudit.setAccElecSellTicket(swAuItvmOnlineAmountHierarchyDifference.getReplyComparativeSaleMoney());
            }else if("1".equals(tableDataSource) || "5".equals(tableDataSource)
                    || "6".equals(tableDataSource)){

            }
            int i = swAuTvmAmountDefferenceMapper.updateById(fareDifferencesInAudit);
            SwAuItvmOnlineAmountHierarchyDifference s=new SwAuItvmOnlineAmountHierarchyDifference();
            s.setReplaceStatus("1");
            s.setId(swAuItvmOnlineAmountHierarchyDifference.getId());
            //修改替换状态
            swAuItvmOnlineAmountHierarchyDifferenceMapper.updateById(s);
            }
        }catch (Exception e){
            log.error("{}",e);
            result.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
            result.appendMsg("票款差异审核主表替换失败！");
        }
        return result;
    }
}
